<?php
class Shipping_Service_ShipFeeCalc{
    private $_warehouseId;         //仓库ID
    private $_countryId;           //国家ID
    private $_stId;                //货运方式ID
    private $_weight;              //重量
    private $_length;              //长
    private $_width;               //宽
    private $_height;              //高
    private $_customerId;          //客户ID
    private $_stCodeClass;         //货运方式分类
    private $_stSort;              //货运方式排序方式
    private $_array;               //数组

    public function __construct($array){
        if($array!=null){
			foreach($array as $key=>$val){
				$this->set('_'.$key,$val);
			}
		}
        $this->_array = $array;
	}

    public function set($key,$value){
		$this->$key =$value;
	}
    /*获取错误信息*/
    public function getError($code=0){
        $error=array(
            '0'=>'Data Error'.$code,
            '-1'=>'Country does not exist',
            '-2'=>'Shipping method does not exist',
            '-3'=>'Incorrect Weight',
            '-4'=>'The shipping method is not available for this country',
            '-5'=>'No Price',
            '-6'=>'Please choose shipping method first',
        );
        if(!isset($error[$code])){
            return $error[0];
        }
        return $error[$code];
    }
    /*
    *根据仓库ID,国家ID,货运方式ID,重量,长,宽,高,客户ID获取运费
    */
    public  function calcFeeByType(){
    	$inter = new Shipping_Service_InterFeeCalc($this->_array);
        $fee = $inter->getRate();
        if(!is_array($fee)){
            $fee=$this->getError($fee);
        }
        return $fee;
    }

    /*
    *根据仓库ID,国家ID,重量,长,宽,高,客户ID获取货运方式及运费
    */
    public  function calcFee(){

    	$inter = new Shipping_Service_InterFeeCalc($this->_array);
        $fees = $inter->getAllRate();
        return $fees;
    }

    /*
    *根据仓库ID,国家ID,货运方式类型,重量,长,宽,高,客户ID获取货运方式及运费
    */
    public  function calcFeeByClass(){

    	$inter = new Shipping_Service_InterFeeCalc($this->_array);
        $fees = $inter->getByClass();
        return $fees;
    }

    /*
    *根据仓库ID,国家ID,排序类型,重量,长,宽,高,客户ID获取货运方式及运费
    */
    public  function calcFeeBySortType() {
        $inter = new Shipping_Service_InterFeeCalc($this->_array);
        $fees = $inter->getBySortType();
        return $fees;
    }

    /*
    *根据仓库ID,国家ID　可用的货运方式;
    */
    public  function getAviableType(){
        $inter = new Shipping_Service_InterFeeCalc($this->_array);
        $shipType =  $inter->getAvailShipType();
        return $shipType;
    }
}